#include <iostream>

#include "Operand.h"
#include "RegularExperssion.h"

void test_union(){
    CharOperand s1{'a','b'};
    CharOperand s2{'C','D'};
    RegularExpression re(&s1,'|',&s2);
    re.get_graph()->display_NFA();
}

void test_link(){
    CharOperand s1{'a','b'};
    CharOperand s2{'C','D'};
    RegularExpression re(&s1,'-',&s2);
    //re.get_graph()->display_NFA();
    re.link_regular(&s1);
    re.get_graph()->display_NFA();

    RegularExpression re_one=re;
    re.link_regular(&re_one);
    re.get_graph()->display_NFA();
}

void test_closure(){
    CharOperand s1{'a','b'};
    RegularExpression re(&s1,'*');
    re.get_graph()->display_NFA();

    //另一种调用
    // CharOperand s1{'a','b'};
    // RegularExpression re(&s1);
    // re.closure_regular();
    // re.get_graph()->display_NFA();
}

void test_closure_b(){
    CharOperand s1{'a','b'};
    RegularExpression re(&s1,'*');
    re.get_graph()->display_NFA(); //无出边，无入边
    re.closure_regular();
    re.get_graph()->display_NFA();//有出边，有入边


}

void test_zero_or_one_b(){
    CharOperand s1{'a','b'};
    RegularExpression re(&s1,'*');
    re.zero_or_one_regular();//有出边，有入边
    re.get_graph()->display_NFA();
}

void test_plus_closure(){
    CharOperand s1{'a','b'};
    RegularExpression re(&s1,'+');
    re.get_graph()->display_NFA();
}

void test_one_or_zero(){
    CharOperand s1{'a','b'};
    RegularExpression re(&s1,'?');
    re.get_graph()->display_NFA();
}

void test_aab(){
    CharOperand s{'a','b'};
    RegularExpression re(&s,'*'); // (a|b)*
    //re.get_graph()->display_NFA();
    CharOperand a{'a'};
    CharOperand b{'b'};
    re.link_regular(&a);
    //re.get_graph()->display_NFA();
    re.link_regular(&a);
    //re.get_graph()->display_NFA();
    re.link_regular(&b);
    re.get_graph()->display_NFA();

    DFAGraph dnf=move(re.get_graph()->NFAtoDFA());
    dnf.display_DFA();
}

void homework7(){
    CharOperand ch1{set<char>{'a','e','i','o','u'}};
    RegularExpression answer1{&ch1};
    answer1.closure_regular();
    //answer1.get_graph()->display_DFA_NFA();

    CharOperand ch7{'a'};
    CharOperand ch9{'b'};

    
    RegularExpression temp_b{&ch9,'?'}; // b?
    RegularExpression temp{&ch7,'-',&temp_b}; //a(b)?
    temp.closure_regular(); // (a(b)?)*
    RegularExpression answer{&ch9,'*'}; // b*
    answer.link_regular(&temp);
    answer.get_graph()->display_DFA_NFA();
}

void homework8(){
    CharOperand ch7{'a'};
    CharOperand ch8{};
    CharOperand ch9{'b'};
    RegularExpression temp1{&ch7,'*'}; // a*

    RegularExpression answer7{&ch9,'*'}; // b*

    
    RegularExpression temp2(&ch9,'?'); // (b)?
    
    RegularExpression answer8{&answer7,'-',&temp1};//b*a*
    answer8.link_regular(&temp2); // b* a* (b)?
    answer8.link_regular(&temp1);// b* a* (b)? (a)*
    answer8.get_graph()->display_DFA_NFA();
}
int main(){
    //homework7();
    cout<<" \n\ngap\n\n";
    homework8();


    return 0;
}

